#include<iostream>
using namespace std;
class CVector {
private:
	int* data;
	int n;
	static int sum;
public:
	CVector();
	void print();
	static int getsum() {
		return sum;
	}
	CVector(int n1, int* a);
	~CVector();
};
int CVector::sum = 0;
CVector::CVector() {
	n = 5;
	data = new int[n];
	for (int i = 0; i < n; i++) {
		data[i] = i;
	}
}
CVector::CVector(int n1, int* a) {
	n = n1;
	data = new int[n1];
	for (int i = 0; i < n1; i++) {
		data[i] = a[i];
		sum += a[i];
	}
}
void CVector::print() {
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			cout << data[i] << endl;
		}
		else {
			cout << data[i] << ' ';
		}
	}
}
CVector::~CVector() {
	sum = 0;
	delete[] data;
}
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		int sum = 0;
		for (int j = 0; j < n; j++) {
			int m;
			cin >> m;
			int* a = new int[m];
			for (int k = 0; k < m; k++) {
				cin >> a[k];
			}
			CVector C(m, a);
			C.print();
			sum += C.getsum();
		}
		cout << sum << endl;
	}
	return 0;
}